<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="/res/third/easyUI/themes/default/easyui.css"
	rel="stylesheet" type="text/css" />
<link href="/res/third/bootstrap3/css/bootstrap.min.css"
	rel="stylesheet" type="text/css" />
<link href="/res/third/zTree/3.5/zTreeStyle.css" rel="stylesheet"
	type="text/css" />
<style>
.uploadpic {
	width: 73px;
	height: 30px;
	text-align: center;
	font-weight: bold;
	background-color: #337ab7;
	color: #fff;
	line-height: 30px;
	border-radius: 5px;
	cursor: pointer;
}

.edit_attachfile {
	width: 100px;
	height: 100px;
}

th {
	width: 150px;
	text-align: center;
	display: table-cell;
	vertical-align: middle !important;
}
</style>
</head>
<body>
	<form id="editform">
		<input type="hidden" id="id"
			value='[#if probrand??]${probrand.id!}[/#if]' name="id">
		<table class="table table-hover table-bordered">
			<tr>
				<th>*所属类目：</th>
				<td height="250px"><ul style="height: 250px; overflow: auto;"
						id="tt" class="ztree">

					</ul></td>
			</tr>
			<tr>
				<th>*品牌名称：</th>
				<td><input id="name" name="name" maxlength="64" required="required"
					value="[#if probrand??]${probrand.name!}[/#if]" /></td>
			</tr>
			<tr>
				<th>*品牌排序：</th>
				<td><input id="seq" name="seq" maxlength="11" required="required"
					value="[#if probrand??]${probrand.seq!}[/#if]" /></td>
			</tr>
			<tr>
				<th>*品牌封面：</th>
				<td>
					<div>
						<img id="edit_attachfile" class="edit_attachfile" src="[#if probrand??]${probrand.attachfile!}[#else][/#if]" />
						<div style="display: inline-block" class="uploadpic"
							onclick="uploaddialog()">上传图片</div>
					</div> <input type="hidden" id="attachfile" name="attachfile"
					required="required" value="[#if probrand??]${probrand.attachfile!}[#else][/#if]" />
				</td>
			</tr>
			[#--<tr>
				<th>*是否是自营品牌：</th>
				<td><input type="radio" name="ifSelf" value="1" [#if
					probrand?? ] [#if probrand.ifSelf==1]checked="checked"[/#if][/#if]>是
					<input type="radio" name="ifSelf" value="0" [#if probrand?? ] [#if
					probrand.ifSelf==0]checked= "checked"[/#if][#else]checked="checked"[/#if]>否
				</td>
			</tr>
			<tr>
				<th>*是审核状态：</th>
				<td><input type="radio" name="state" value="1" [#if
					probrand?? ] [#if probrand.state==1]checked="checked"[/#if][/#if]>是
					<input type="radio" name="state" value="0" [#if probrand?? ] [#if
					probrand.state==0]checked= "checked"[/#if][#else]checked="checked"[/#if]>否
				</td>
			</tr>--]
		</table>
	</form>
	<div class="center-block">
		<button type="button" class="btn btn-success" onclick="submit()">提交</button>
	</div>
</body>
</html>
<script src="/res/common/js/jquery.1.9.1.min.js" type="text/javascript"></script>
<script src="/res/third/artDialog/jquery.artDialog.js"
	type="text/javascript"></script>
<script src="/res/third/zTree/3.5/jquery.ztree.all.min.js"
	type="text/javascript"></script>
<script src="/res/third/validate/jquery.validate.js"
	type="text/javascript"></script>

<script type="text/javascript">
	$(function() {
		var setting = {
			data : {
				simpleData : {
					enable : true,
					idKey : "id",
					pIdKey : "pid",
					rootPId : 0
				}
			},
			check : {
				enable : true,
				chkStyle : "checkbox",
				chkboxType : {
					"Y" : "ps",
					"N" : "ps"
				},
				radioType : "all"
			}
		};

		$.ajax({
			url : "/category/v_ztree.do?id="+$("#id").val(),
			type : "get",
			dataType : "json",
			success : function(data) {
				$.fn.zTree.init($("#tt"), setting, data);
			}
		});

	});

	function uploaddialog() {
		updialog = art.dialog.uploadFile("上传图片", {
			callback : "uploadCallBack",
			userpath : "admin",
			extensions : "gif,jpg,png,jepg"
		});
	}

	function uploadCallBack(response) {
		updialog.close();
		$("#edit_attachfile").attr("src", response.url);
		$("#attachfile").val(response.url);
	}

	function filter(node) { //过滤器直选中3级节点累加  
		return (node.level == 2 && node.checked == true);
	}

	function submit() {
		var editform = $("#editform");
		var zTreeO = $.fn.zTree.getZTreeObj("tt").getNodesByFilter(filter);
		var ztreeArray = [];
		for (var i = 0; i < zTreeO.length; i++) {
			var ztree = {};
			if (zTreeO[i].id != null) {
				var categoryTId = zTreeO[i].id;
				var categorySId = zTreeO[i].getParentNode().id;
				var categoryFId = zTreeO[i].getParentNode().getParentNode().id;
				ztree.categoryTId = categoryTId;
				ztree.categorySId = categorySId;
				ztree.categoryFId = categoryFId;
				ztreeArray.push(ztree);
			}
		}
		var data={};
		data.ztreeArray=JSON.stringify(ztreeArray);
		data.id=$("#id").val();
		data.name=$("input[name='name']").val();
		data.seq=$("input[name='seq']").val();
		data.attachfile=$("input[name='attachfile']").val();
		data.ifSelf=$("input[name='ifSelf']").val();
		data.state=$("input[name='state']").val();
		//jquery.validate.js验证必填，隐藏域是不验证的
		if (editform.valid()) {
			if (ztreeArray.length <=0) {
				art.dialog.tips("请选择分类");
				return false;
			}
			// Modify 20170321 修改为不必填
//			if ($("#attachfile").val() == '') {
//				art.dialog.tips("请上传文件");
//				return false;
//			}
			$.ajax({
				url : '/brandmanager/o_saveBrand.do',
				type : 'post',
				dataType : 'json',
				async : false,
				contentType : 'application/json; charset=utf-8',
				data :  JSON.stringify(data),
				success : function(data) {
					art.dialog.tips("保存成功");
					location.href = "/brandmanager/v_list.do";
				}
			});
		}
	}
</script>

